package com.qf.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticsearchClient {

    @Value("${es.host}")
    private String esHost;

    @Value("${es.port}")
    private Integer esPort;

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        // 1.设置es的ip和端口
        HttpHost httpHost = new HttpHost(esHost,esPort);

        // 2.构建一个对象
        RestClientBuilder builder1 = RestClient.builder(httpHost);

        // 3.获取RestHighLevelClient
        RestHighLevelClient client = new RestHighLevelClient(builder1);

        return client;
    }

}
